package com.bizihang.chain.support;

import com.bizihang.chain.Filter;
import com.bizihang.chain.FilterChain;

import java.util.Collections;
import java.util.List;

/**
 * 过滤器链的默认实现
 *
 * @author 毕子航 951755883@qq.com
 * @date 2018/11/01
 */
public class DefaultFilterChain implements FilterChain {
	private List<Filter> filters = Collections.EMPTY_LIST;

	private int position = 0;

	public DefaultFilterChain(List<Filter> filters) {
		this.filters = filters;
	}

	public void doFilter() {
		if (this.filters != null && position < this.filters.size()) {
			this.filters.get(position++).doFilter(this);
		}
	}

	protected List<Filter> getFilters() {
		return filters;
	}


	protected int getPosition() {
		return position;
	}
}
